package com.ruoyi.jksd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jksd.domain.XyGoodsList;
import com.ruoyi.jksd.service.IXyGoodsListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品管理Controller
 *
 * @author ruoyi
 * @date 2024-05-26
 */
@RestController
@RequestMapping("/jksd/googdslist")
public class XyGoodsListController extends BaseController {
    @Autowired
    private IXyGoodsListService xyGoodsListService;

    /**
     * 查询商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('jksd:googdslist:list')")
    @GetMapping("/list")
    public TableDataInfo list(XyGoodsList xyGoodsList) {
        startPage();
        List<XyGoodsList> list = xyGoodsListService.selectXyGoodsListList(xyGoodsList);
        return getDataTable(list);
    }

    /**
     * 导出商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('jksd:googdslist:export')")
    @Log(title = "商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XyGoodsList xyGoodsList) {
        List<XyGoodsList> list = xyGoodsListService.selectXyGoodsListList(xyGoodsList);
        ExcelUtil<XyGoodsList> util = new ExcelUtil<XyGoodsList>(XyGoodsList.class);
        util.exportExcel(response, list, "商品管理数据");
    }

    /**
     * 获取商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('jksd:googdslist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xyGoodsListService.selectXyGoodsListById(id));
    }

    /**
     * 新增商品管理
     */
    @PreAuthorize("@ss.hasPermi('jksd:googdslist:add')")
    @Log(title = "商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XyGoodsList xyGoodsList) {
        return toAjax(xyGoodsListService.insertXyGoodsList(xyGoodsList));
    }

    /**
     * 修改商品管理
     */
    @PreAuthorize("@ss.hasPermi('jksd:googdslist:edit')")
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XyGoodsList xyGoodsList) {
        return toAjax(xyGoodsListService.updateXyGoodsList(xyGoodsList));
    }

    /**
     * 删除商品管理
     */
    @PreAuthorize("@ss.hasPermi('jksd:googdslist:remove')")
    @Log(title = "商品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xyGoodsListService.deleteXyGoodsListByIds(ids));
    }


    public AjaxResult proOrder() {
        LoginUser loginUser = getLoginUser();

       return success(xyGoodsListService.preOrder(loginUser));
    }
}
